home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
F1 Licenseware
/
F1 Licenseware - Volume 1.iso
/
disks
/
089a.dms
/
089a.adf
/
TEXTS
/
CHAPTERS_21-30
/
Chapter25.txt
< prev
next >
Wrap
Text File
|
1992-03-06
|
8KB
|
246 lines
The Absolute Beginners Guide To Amos
-------------------------------------
Chapter Twenty Five
----------------------
Here are a few random bits and pieces that need mentioning before we venture
on in to more advanced territory.
I have covered the IF THEN statement a lot but only mentioned in passing the
IF-END IF structure. Take a look at the two examples below.
REM IF THEN example
'------------------
IF A=1 THEN PRINT" A is equal to one":CLEAR KEY: WAIT KEY: CLS 0: STOP
REM IF END IF example
'-------------------
IF A=1
PRINT" A is equal to one"
CLEAR KEY: WAIT KEY
CLS 0
STOP
END IF
As you may imagine END IF can be useful if you have a lot of things to do
between a IF and a THEN statement which you would either have to fit on to
one line or call a subroutine or procedure. What IF-END IF comes down to is
that the lines of code between the IF and the END IF will ONLY be executed
If the IF condition is true. If the IF part is false then Amos will look
for the END IF instruction and jump to the next line after that.
EXIT IF
------
Another benefit of IF-END IF is the EXIT IF structure.
This can EXIT the IF-END IF structure at any stage, for example:
EXIT IF a>1
That's enough of that we have learnt quite a few control structures
recently and I don't want to bog you down.
DIRECT
------
I have used the EDIT instruction quite a lot in the Example programs but not
the DIRECT instruction, which is the same as pressing escape from the editor.
It's pretty useless but now you know.
INVERSE
-------
INVERSE is a very simple instruction indeed. What it does is swap the
colour of your text with the background colour. For example, if you had a
black screen and printed some white text on it INVERSE ON would make the
text in PAPER white and PEN black:
INVERSE ON
PRINT" INVERSED"
INVERSE OFF
PRINT"NORMAL"
Don't forget everything you PRINT will come out INVERSED until you issue
the INVERSE OFF instruction, similar to the UNDER ON/OFF instruction in
usage.
HOME
----
Using the instruction HOME is the same as using LOCATE 0,0: It sets the text
cursor to the top left hand corner of the screen.
CLINE
-----
CLINE is a very useful instruction. It CLears the LINE on which the text
cursor is currently positioned on. An optional parameter can be used to tell
CLINE how much of the line is to be cleared:
CLINE (Clear the whole line)
or
CLINE 12 (Clear 12 characters of the line)
The text cursor position is unaffected by CLINE.
TIMER and RANDOMIZE
-------------------
TIMER is a system variable that is incremented every 50th of a second.
TIMER starts as soon as you switch on your Amiga, even before you load Amos!
It has it's uses, but is most used in conjunction with the RANDOMIZE
instruction. The RND function is what is known as a pseudo random number
generator. The numbers given by RND are random enough for most uses but in
something like a card game it's limitations would be exposed.
RND eventually loops and reproduces a set sequence of numbers.
To get around this RND can be given a new seed to gather it's sequence from.
This is where TIMER comes in handy as TIMER is a continually changing number,
so to ensure a good RND sequence we just do this:
RANDOMIZE TIMER
PARENT
------
PARENT is a instruction that is useful if you are wading through a disk full
of drawers. Say for instance you wanted to look inside your pictures drawer:
DIR$="PICTURES/"
DIR
But now you want to return to the root directory, all you do is:
PARENT
In that example we could have just issued a DIR$="DF0:" or whatever to get
the same effect but where PARENT is more useful is if you are in a drawer of
a drawer and just want to return to the first drawer:
DIR$="PICTURES/HAMPICS/"
DIR
PARENT
Would leave you inside the pictures drawer and not the hampics drawer.
By the way the DIR instruction simply prints a DIRectory listing of the
contents of the current directory to the screen.
RUN
---
A quick word about the RUN instruction. This is useful if you want to chain
a lot of programs together. Here is an example:
RUN "LEVEL1.Amos"
And when LEVEL1 has been completed you RUN "LEVEL2.Amos" from there. The RUN
instruction can only be used with Amos compiled code and not executable
compiled code so is of limited use.
============================================================================
To keep you interested I have knocked up a simple program that you can get
to work on and practice some of the commands you have recently learnt.
I have commented every part of the listing here and in Example25.Amos.
You shouldn't have too much trouble understanding it. If you get stuck
anywhere look up the command(s) in your note book, failing that look them
up in the index and re-read the relevant chapters. I am not going to suggest
what you should do with it, just experiment and see how far you can get.
Have fun.
'The beginnings of a ship thingy. It could be anything you want!
Rem Hide the mouse pointer and unpack the picture I have stored in bank 10
Rem Set double buffer on to cut down on flicker.
'-------------------------------------------------------------------------
Hide
Unpack 10 To 0
Double Buffer
Rem Set the following variables to be used inside and outside
Rem of procedures.
'-------------------------------------------------------------
Global XOFF,YOFF
Rem Set up the variables:
Rem XOFF is the x offset of the screen display
Rem YOFF is Y offset
Rem AC is the x position of the ship
Rem DWN is the y position of the ship
Rem IMAGE is the bob bank image number being used for the ship
Rem Image 2 is the ship facing right, Image 3 facing left
Rem X means horizontal,left<>right, Y means vertical.
'--------------------------------------------------------------
XOFF=0 : YOFF=0 : AC=100 : DWN=150 : IMAGE=2
Rem The main loop
'----------------
REM Start the DO-LOOP structure.
'--------------------------------
Do
Rem place Bob 1 at the coordinates ac,dwn (across,down) Image will
Rem be set to the correct direction.
'----------------------------------------------------------------------
Bob 1,AC,DWN,IMAGE
Rem Now deal with the joystick. We are only interested in left and right
Rem movement.
Rem If pressed to right then we INCrease xoff by one, update the bobs
Rem position by INCreasing AC then make sure IMAGE is equal to 2 pointing
Rem right.
'------------------------------------------------------------------------
If Jright(1) Then Inc XOFF : Inc AC : IMAGE=2
Rem Joystick left is virtually the same except using DECrease and image 3
'---------------------------------------------------------------------------
If Jleft(1) Then Dec XOFF : Dec AC : IMAGE=3
Rem The following lines make sure the ship stays inside the screen.
Rem If AC=0 then the ship has reached the left edge of the screen to stop
Rem it going off the edge we make sure AC stays at a minimum of 0.
Rem The right is 896 we do the same. It's 896 because the loaded picture is
Rem that wide, I created the picture in DPAINT and using the screen size
Rem settings set the width to 896 this.
'---------------------------------------------------------------------------
If AC<0 Then AC=0
If AC>896 Then AC=896
Rem call the _UPD procedure which scrolls the screen
'---------------------------------------------------
_UPD
Rem Wait Vbl slows things down and keeps it smooth.
Rem Try the game without it and see what you think.
'----------------------------------------------------
Wait Vbl
Rem The end of the main loop, jumps back to the DO command.
'----------------------------------------------------------
Loop
Procedure _UPD
Rem This stops the screen scrolling too far like in the AC bit above
'-------------------------------------------------------------------
If XOFF<0 Then XOFF=0
If XOFF>620 : XOFF=620 : End If
If YOFF<0 Then YOFF=0
If YOFF>200 : YOFF=0 : End If
Rem This is what scrolls the background,
'-----------------------------------------
Screen Offset 0,XOFF,YOFF
End Proc
End of Chapter 25
^^^^^^^^^^^^^^^^^